/*
 * @Author: greyqiu greyqiu@163.com
 * @Date: 2023-06-29 17:12:26
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-08-07 10:38:51
 * @FileName: ledtask.c
 * @Description: 
 * y
 * Copyright (c) 2023 by GreyQiu, All Rights Reserved. 
 */
#include "bsp.h"
#include "easy_timer.h"
#include "ledtask.h"
#include "app_analog.h"
#include "fault.h"

EASY_TIMER_DEF(eeprom_test_tmr);
EASY_TIMER_DEF(analog_tmr);
EASY_TIMER_DEF(fault_tmr);


uint8_t read_test[8] = {0};

static void eeprom_test(void) {
    static uint8_t buf_test[8] = {
        0x80, 0x81, 0x82, 0x83, 0x84, 0x85 ,0x86, 0x87
    };
    eprm_sts_t sts;
    sts = bsp_eeprom_page_erase(0); // 擦除
    if (sts != EPRM_SUCCESS) {
        log_debug("erase err code = %d", sts);
        return;
    }

    sts = bsp_eeprom_write(0, buf_test, 8); // 编程
    if (sts != EPRM_SUCCESS) {
        log_debug("write err code = %d", sts);
        return;
    }

    bsp_eeprom_read(0, read_test, 8); // 回读
    for (uint8_t i = 0; i < 8; i++) {
        log_debug("0x%02x  ", read_test[i]);
    }

    log_debug("\n");
}

static void analog_signal_task(void) {
    for (uint8_t i = 0; i < ANALOG_ID_NUM; i++) {
        log_debug("%f  ", asignal_get_real_flt(i));
    }
    log_debug("---\n");
} 

void ledtask_init(void) {
    // easy_timer_create(eeprom_test_tmr);
    // easy_timer_start(eeprom_test_tmr, 1000, EASY_TIMER_MODE_REPEATED, eeprom_test, NULL);
    app_analog_init();
    bsp_pwm_output_enable();
    easy_timer_create(analog_tmr);
    easy_timer_start(analog_tmr, 1000, EASY_TIMER_MODE_REPEATED, analog_signal_task);
}
